<template>
    <div class="poor-apply">
        <SelectSearch @resetData="getPoorAppliyData" @searchData="getPoorAppliyData"></SelectSearch>
        <el-card>
            <el-table ref="multipleTable" class="custom-table" height="450px"
                :default-sort="{ prop: 'date', order: 'descending' }"
                :header-cell-style="{ background: '#f5f7fa', color: '#606266' }" :data="tableData" tooltip-effect="dark"
                style="width: 100%">
                <el-table-column prop="id" label="序号" width="80" sortable>
                </el-table-column>
                <el-table-column prop="username" label="申请用户" width="100">
                </el-table-column>
                <el-table-column prop="apyExplain" label="申请说明" width="200" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="createdDt" label="申请时间" width="170">
                </el-table-column>
                <el-table-column prop="apyMaterial" label="申请资料">
                    <template slot-scope="scope">
                        <el-button type="warning" size="mini" @click="handleDown(scope.row)">下载资料</el-button>
                    </template>
                </el-table-column>
                <el-table-column prop="reviewStatus" label="审核状态" width="150">
                    <template slot-scope="scope">
                        <span v-if="scope.row.reviewStatus == 0">待审核</span>
                        <span v-if="scope.row.reviewStatus == 1">审核通过</span>
                        <span v-if="scope.row.reviewStatus == 2">审核不通过</span>
                        <span v-if="scope.row.reviewStatus == 3">已撤销申请</span>
                    </template>
                </el-table-column>
                <el-table-column prop="reviewExplain" label="审核说明" width="150" show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" v-if="scope.row.reviewStatus == 0" size="mini"
                            @click="handleEdit(scope.row)" plain>审核</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <Pagination :paginationData="paginationData" @getPaginationData="getPoorAppliyData"></Pagination>
        </el-card>
        <ApplyDialog @editPoorApply="editPoorApply"></ApplyDialog>
    </div>
</template>
<script>
import SelectSearch from '../../components/select_search/index.vue'
import Pagination from '../../components/pagination/index.vue'
import ApplyDialog from './dialog/index.vue'
export default {
    name: 'PoorApply',
    components: {
        SelectSearch,
        Pagination,
        ApplyDialog
    },
    mixins: [],
    props: {

    },
    data() {
        return {
            tableData: [],
            multipleSelection: [],
            paginationData: {},
            placeholder: '请输入标题查询'
        }
    },
    computed: {

    },
    watch: {

    },
    mounted() {
        this.getPoorAppliyData()
    },
    methods: {
        // 获取贫困户申请列表
        getPoorAppliyData(obj = { currentPage: 1, pageSize: 10, keyword: '' }) {
            this.request.post('/poorApplyInfo/selectAllApplyInfoPage', obj).then(res => {
                if (res.code == 20000) {
                    res.data.list.forEach(item => {
                        if (item.createdDt) {
                            let font = item.createdDt.slice(0, 10)
                            let after = item.createdDt.slice(11)
                            item.createdDt = font + ' ' + after
                        }
                    })
                    this.tableData = res.data.list
                    this.paginationData = res.data
                }
            })
        },
        // 审核 贫困户申请
        editPoorApply(obj) {
            this.request.post('/poorApplyInfo/orderAdit', obj).then(res => {
                if (res.code == 20000) {
                    // 重新获取公告列表
                    this.getPoorAppliyData()

                }
            })
        },
        // 编辑信息
        handleEdit(row) {
            this.$bus.$emit('add', true)
            this.$bus.$emit('getForm', row)
        },
        // 下载资料
        handleDown(row) {
            const a = document.createElement("a");
            const event = new MouseEvent("click");
            a.download = row.attachmentName;
            a.href = row.apyMaterial;
            a.dispatchEvent(event)
        }
    }
};
</script>
<style lang='' scoped>
</style>